<template>
	<view>


		<view class="search-wrap">
			<u-search height="32" bg-color='#fff' placeholder="搜索客户" :show-action="false" :action-style="{color: '#fff'}"
				@change="search" v-model="keyword"></u-search>
			<resource-select></resource-select>
		</view>

		<view class="resourceListTop" :style="{'height':navTopHeight +'px'}">

			<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom"
				refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="45"
				refresher-background="transparent" @refresherpulling="onPulling" @refresherrefresh="onRefresh"
				@refresherrestore="onRestore" @refresherabort="onAbort">
				<view class="viewWrap">
					<view class="page-box" id="tabInList">
						<view class="order" @click="goDetail(res)" v-for="(res, index) in goods" :key="index">
							<view class="top">
								<view class="left">
									<u-icon name="star" color="#ff9900"></u-icon>
									<view class="store">刘海涛{{index}}</view>
								</view>
								<view class="right">
									12000元/㎡
								</view>
							</view>


							<view class="bottom">

								<view class="u-border-right">3室2厅2卫</view>

								<view class="u-center">120㎡</view>

								<view class="u-border-left">2/2F</view>

							</view>


						</view>
						<u-loadmore :status="loadStatus" bgColor="#f2f2f2"></u-loadmore>


					</view>

				</view>
			</scroll-view>

		</view>



	</view>
</template>

<script>
	import resourceSelect from '@/components/resource/resourceSelect.vue'
	export default {
		data() {
			return {
				triggered: false,
				navTopHeight: null,
				navbarHeight: null,
				keyword: '',
				goods2: [],
				goods: [],
				loadStatus: 'loadmore',
			}
		},
		components: {
			resourceSelect
		},


		created() {

			this._freshing = false;
			this.triggered = true;
			// setTimeout(() => {
			// 	this.triggered = true;
			// }, 1000)
			this.getOrderList();
		},
		mounted() {
			this.setNavTop()
		},




		methods: {
			goDetail(res) {
				console.log('222')
				uni.navigateTo({
					url: '/pages/customersThread/customersDetail'
				});
			},

			onPulling(e) {
				console.log("onpulling", e);
			},
			onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
				}, 1000)
			},
			onRestore() {
				this.triggered = 'restore'; // 需要重置
				console.log("onRestore");
			},
			onAbort() {
				console.log("onAbort");
			},

			reachBottom() {
				// 此tab为空数据

				this.loadStatus = "loading"
				setTimeout(() => {
					this.getOrderList();
				}, 1200);

			},


			// 设置nav到顶部的距离 (滚动条为0, 菜单顶部的数据加载完毕获取到的navTop数值是最精确的)
			setNavTop() {

				// uniapp的方法
				let _this = this

				setTimeout(() => {
					uni.getSystemInfo({
						success: function(res) { // res - 各种参数
							const query = uni.createSelectorQuery().in(_this);

							query.select('.resourceListTop').boundingClientRect(function(
								data) { // data - 各种参数


								_this.navTopHeight = res.windowHeight - data.top -
									10 // 到屏幕顶部的距离
							}).exec()
						}
					})
				}, 100)





			},


			search(val) {
				console.log(val)
			},

			// 页面数据
			getOrderList() {
				if (this.goods.length > 20) {
					this.loadStatus = "nomore"

				} else {
					for (let i = 0; i < 8; i++) {
						this.goods.push(i);
					}
					this.loadStatus = "loadmore"
				}

			}
		}
	}
</script>


<style lang="scss" scoped>
	.uTabsClass {
		width: 100%;
	}

	.viewWrap {
		overflow-y: auto;
	}

	// .scroll-Y{
	// 	height: calc(100vh - var(--window-top));
	// }


	.swiperBar {
		width: 100%;
	}

	.search-wrap {
		box-sizing: border-box;
		padding: 20rpx 20rpx;

	}

	.page-box {
		padding: 0 20rpx;
	}

	.order {
		background-color: #ffffff;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;
			.left {
				display: flex;
				align-items: center;
				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
				}
			}
			.right {
				display: flex;
			}
		}
		.bottom {
			margin-top: 15px;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			color: #909193;

			.u-border-right {
				padding-right: 10rpx;
			}
			.u-center {
				padding: 0 10rpx;
			}

			.u-border-left {

				padding-left: 10rpx;
			}
		}
	}

	.resourceListTop {
		display: flex;
		flex-direction: column;
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>
